package analysis;

import common.AnalysisWare;
import redis.clients.jedis.Tuple;
import common.Constants;
import common.DataAnalysis;
import util.FileUtil;
import util.PropertiesUtil;
import util.redis.RedisUtil;
import util.remote.RemoteConnectResult;

import java.util.Set;

/**
 * Created by J.Chen on 2017/5/22.
 */

@AnalysisWare(confCode = "ACT_2016_12_LUCKY_STAGE", desc = "幸运舞台")
public class LuckStageAnalysis extends DataAnalysis {

    public LuckStageAnalysis(RemoteConnectResult result, String confCode) {
        super(result, confCode);
        String week = PropertiesUtil.getAnalysisConfValue(confCode, "weekIndex");
        weekIndex = Integer.parseInt(week);
    }

    private int weekIndex;

    public void setWeekIndex(int weekIndex) {
        this.weekIndex = weekIndex;
    }

    @Override
    public void execute() {
        RedisUtil jedis = result.getRedisUtil();
        FileUtil fileUtil = new FileUtil(Constants.getActOutputDir(result.getRemoteConf(), actConf.getConfCode(), "" + weekIndex));
        Set<Tuple> set = jedis.zrevrangeWithScores(String.format("zAct:lucky:stage:rank:%d", weekIndex), 0, 19);
        for (Tuple s : set) {
            String nick = jedis.hget("muser_info:" + s.getElement(), "nickname");
            fileUtil.writeln("\t\t\t", nick, "" + new Double(s.getScore()).intValue());
        }
        fileUtil.close();


    }
}
